package com.ymatou.userregister.service;

import java.util.Map;

import com.google.gson.Gson;
import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymttest.utils.EnvSetup;

/**
 * 洋码头用户注册接口Call
 * @author chenshuangyan
 *
 */
public class YmatouUserRegCall extends YmatouBaseCall {
	private static String opurl = "json/reply/UserRegisterInfoRequestDto";

	public YmatouUserRegCall() {
		super(EnvSetup.getSystemUrl("api_userregister"), opurl, "POST", "JSON");
	}

	@Override
	public void addDefHeader() {
		client.addHeader("Accept", "text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}
	
	/**
	 * 返回用户ID
	 * @return
	 */
	public int getUserId(){
		int userid=0;
		Map user = new Gson().fromJson(getString("Result"), Map.class);
		try{
			userid=((Double)user.get("UserId")).intValue();
		}catch(Exception e){
			Logger.debug("获取userid失败:"+e.getMessage());
		}
		return userid;
	}
	
	/**
	 * 返回登陆token信息
	 * @return
	 */
	public String getToken(){
		Map user = new Gson().fromJson(getString("Result"), Map.class);
		return user.get("Token").toString();
	}
	
	public Map getResult(){
		Map result = (Map) FormatUtil.GSONToObject(getString("Result"), Map.class);
		return result;
	} 
	
}
